package cn.tedu.egmvc01.controller;

import cn.tedu.egmvc01.mapper.EmperMapper;
import cn.tedu.egmvc01.pojo.entity.Emper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@Controller
public class EmperController {
    @Autowired
    private EmperMapper emperMapper;

    @RequestMapping("emp/insert")
    @ResponseBody
    public String addEmp(Emper emper){
        int i = emperMapper.addEmper(emper);
        if (i==1){
            return "添加成功！";
        }
        return "添加失败";
    }


    @RequestMapping("emp/select")
    @ResponseBody
    public String selectEmp(Integer id){
        Emper emper = emperMapper.selcetEmper(id);
        if (emper!=null)
        return "恭喜，查询成功！";
        return "该员工不存在！";
    }

    @RequestMapping("emp/update")
    @ResponseBody
    public String updateEmp(Emper emper){
        int i = emperMapper.updateEmper(emper);
        if (i==1)
        return "修改成功！";
        return "该员工不存在！";
    }

    @RequestMapping("emp/delete")
    @ResponseBody
    public String deleteEmp(Integer id) {
        int i = emperMapper.deleteEmper(id);
        if (i==1)
        return "删除成功！";
        return "该员工不存在！";
    }
}
